package com.xhd.pool;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.cache.CacheMgr;
import com.xhd.cache.UseCache;
import com.xhd.exception.SystemException;
import com.xhd.server.ServerConfig;
import com.xhd.xml.XMLSerializer;

public class ResourcePool implements UseCache {
	  private static final Log jm9;
	  private HashMap jm367 = new HashMap(4);
	  private HashMap jm368 = null;
	  private HashMap jm369 = null;
	  private HashMap jm370 = null;
	  private HashMap jm371 = null;
	  private HashMap jm372 = null;
	  static  Class jm10;

	  static
	  {
	    Class tmp3_0 = jm10;
	    if (tmp3_0 == null)
	    {
	      
	      try
	      {
	        ResourcePool.jm10 = Class.forName("com.xhd.base.res.ResourcePool");
	      }
	      catch (ClassNotFoundException localClassNotFoundException)
	      {
	        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
	      }
	    }
	    jm9 = LogFactory.getLog(tmp3_0);
	  }
	  private HashMap jm365(String paramString)
	  {
	    HashMap localHashMap = (HashMap)this.jm367.get(paramString);
	    if (localHashMap == null)
	    {
	      localHashMap = new HashMap();
	      this.jm367.put(paramString, localHashMap);
	      if ("error".equals(paramString))
	        this.jm370 = localHashMap;
	      else if ("class".equals(paramString))
	        this.jm369 = localHashMap;
	      else if ("action".equals(paramString))
	        this.jm368 = localHashMap;
	      else if ("1".equals(paramString))
	        this.jm371 = localHashMap;
	      else if ("2".equals(paramString))
	        this.jm372 = localHashMap;
	    }
	    return localHashMap;
	  }

	  private void jm366(String paramString1, String paramString2, Vector paramVector, String paramString3, String paramString4)
	  {
	    if ((paramVector == null) || (paramVector.size() < 1))
	      return;
	    if ((paramString1 != null) && (paramString1.length() < 1))
	      paramString1 = null;
	    HashMap localHashMap = jm365(paramString2);
	    int i = paramVector.size();
	    for (int j = 0; j < i; ++j)
	    {
	      Map localMap = (Map)paramVector.get(j);
	      String str = (String)localMap.get(paramString3);
	      Resource localResource = (Resource)localHashMap.get(str);
	      if (localResource == null)
	      {
	        localResource = new Resource();
	        localResource.RsStr = str;
	        localHashMap.put(str, localResource);
	      }
	      if (!(localResource.makeTexts(localMap, paramString4, paramString1)))
	        continue;
	      jm9.warn("Resource " + paramString2 + " " + str + " repeat!");
	    }
	  }

	  private void jm366(String paramString1, Vector paramVector, String paramString2, String paramString3, String paramString4)
	  {
	    if ((paramVector == null) || (paramVector.size() < 1))
	      return;
	    if ((paramString1 != null) && (paramString1.length() < 1))
	      paramString1 = null;
	    HashMap localHashMap = null;
	    int i = paramVector.size();
	    for (int j = 0; j < i; ++j)
	    {
	      Map localMap = (Map)paramVector.get(j);
	      String str1 = (String)localMap.get(paramString2);
	      localHashMap = jm365(str1);
	      String str2 = (String)localMap.get(paramString3);
	      Resource localResource = (Resource)localHashMap.get(str2);
	      if (localResource == null)
	      {
	        localResource = new Resource();
	        localResource.RsStr = str2;
	        localHashMap.put(str2, localResource);
	      }
	      if (!(localResource.makeTexts(localMap, paramString4, paramString1)))
	        continue;
	      jm9.warn("Resource " + str1 + " " + str2 + " repeat!");
	    }
	  }

	  public void createPool()
	    throws SystemException
	  {
	    CacheMgr.registerCache(this);
	    XMLSerializer localXMLSerializer = null;
	    String str1 = null;
	    Vector localVector1 = null;
	    String str2 = null;
	    String str3;
	    File localFile;
	    FileInputStream localFileInputStream;
	    Vector localVector2;
	    try
	    {
	      localVector1 = ServerConfig.getConfFiles("error");
	      if ((localVector1 != null) && (localVector1.size() > 0))
	        for (int i = 0; i < localVector1.size(); ++i)
	        {
	          str3 = (String)localVector1.get(i);
	          localFile = new File(str3);
	          if ((!(localFile.exists())) && (!(localFile.isFile())))
	            continue;
	          localFileInputStream = new FileInputStream(localFile);
	          localXMLSerializer = new XMLSerializer(localFileInputStream, false);
	          localVector2 = localXMLSerializer.getCollection("errormessage");
	          str1 = localXMLSerializer.getData("include-file");
	          str2 = localXMLSerializer.getData("lang-id");
	          localFileInputStream.close();
	          jm366(str2, "error", localVector2, "messageid", "message");
	          if ((str1 == null) || (str1.length() <= 0))
	            continue;
	          localVector1.add(ServerConfig.getConfFilePath(str1));
	        }
	    }
	    catch (Exception localException1)
	    {
	      localException1.printStackTrace();
	      throw new SystemException("Can't find error conf file!");
	    }
	    try
	    {
	      localFileInputStream = new FileInputStream(new File(ServerConfig.getConfFilePath("class")));
	    }
	    catch (IOException localIOException)
	    {
	      throw new SystemException(10025);
	    }
	    try
	    {
	      localVector1 = ServerConfig.getConfFiles("class");
	      if ((localVector1 != null) && (localVector1.size() > 0))
	        for (int j = 0; j < localVector1.size(); ++j)
	        {
	          str3 = (String)localVector1.get(j);
	          localFile = new File(str3);
	          if ((!(localFile.exists())) && (!(localFile.isFile())))
	            continue;
	          localFileInputStream = new FileInputStream(localFile);
	          localXMLSerializer = new XMLSerializer(localFileInputStream, false);
	          str2 = localXMLSerializer.getData("lang-id");
	          str1 = localXMLSerializer.getData("include-file");
	          localVector2 = localXMLSerializer.getCollection("class");
	          jm366(str2, "class", localVector2, "class_name", "class");
	          localVector2 = localXMLSerializer.getCollection("action");
	          jm366(str2, "action", localVector2, "action_name", "action");
	          localFileInputStream.close();
	          if ((str1 == null) || (str1.length() <= 0))
	            continue;
	          localVector1.add(ServerConfig.getConfFilePath(str1));
	        }
	    }
	    catch (Exception localException2)
	    {
	      localException2.printStackTrace();
	      throw new SystemException(10028, localException2.getMessage());
	    }
	    try
	    {
	      localVector1 = ServerConfig.getConfFiles("resource");
	      if ((localVector1 != null) && (localVector1.size() > 0))
	        for (int k = 0; k < localVector1.size(); ++k)
	        {
	          str3 = (String)localVector1.get(k);
	          localFile = new File(str3);
	          if ((!(localFile.exists())) && (!(localFile.isFile())))
	            continue;
	          localFileInputStream = new FileInputStream(localFile);
	          localXMLSerializer = new XMLSerializer(localFileInputStream, false);
	          str2 = localXMLSerializer.getData("lang-id");
	          str1 = localXMLSerializer.getData("include-file");
	          localVector2 = localXMLSerializer.getCollection("res");
	          localFileInputStream.close();
	          jm366(str2, localVector2, "restype", "resid", "res");
	          if ((str1 == null) || (str1.length() <= 0))
	            continue;
	          localVector1.add(ServerConfig.getConfFilePath(str1));
	        }
	    }
	    catch (Exception localException3)
	    {
	      localException3.printStackTrace();
	      throw new SystemException(10039, localException3.getMessage());
	    }
	    if (this.jm370 == null)
	      throw new SystemException(10021);
	    jm9.trace("Resource error size: " + this.jm370.size());
	    if (this.jm369 == null)
	      throw new SystemException(10026);
	    jm9.trace("Resource class size: " + this.jm369.size());
	    if (this.jm368 == null)
	      throw new SystemException(10027);
	    jm9.trace("Resource action size: " + this.jm368.size());
	    if (this.jm372 == null)
	      throw new SystemException(10038);
	    jm9.trace("Resource String size: " + this.jm372.size());
	  }

	  public String getActionName(int paramInt, String paramString)
	  {
	    Resource localResource = (Resource)this.jm368.get(paramString);
	    if (localResource != null)
	      return localResource.getText(paramInt);
	    return paramString;
	  }

	  public String getClassName(int paramInt, String paramString)
	  {
	    Resource localResource = (Resource)this.jm369.get(paramString);
	    if (localResource != null)
	      return localResource.getText(paramInt);
	    return paramString;
	  }

	  public Resource getErrorMessage(int paramInt)
	  {
	    return ((Resource)this.jm370.get(String.valueOf(paramInt)));
	  }

	  public String getObjTypeName(int paramInt1, int paramInt2)
	  {
	    Resource localResource = (Resource)this.jm371.get(String.valueOf(paramInt2));
	    if (localResource != null)
	      return localResource.getText(paramInt1);
	    return String.valueOf(paramInt2);
	  }

	  public String getString(int paramInt1, int paramInt2)
	  {
	    Resource localResource = (Resource)this.jm372.get(String.valueOf(paramInt2));
	    if (localResource != null)
	      return localResource.getText(paramInt1);
	    return "";
	  }

	  public String getString(int paramInt1, int paramInt2, String paramString)
	  {
	    Resource localResource = (Resource)this.jm372.get(String.valueOf(paramInt2));
	    if (localResource != null)
	      return localResource.getText(paramInt1, paramString);
	    return "";
	  }

	  public String getString(int paramInt1, int paramInt2, String paramString1, String paramString2)
	  {
	    Resource localResource = (Resource)this.jm372.get(String.valueOf(paramInt2));
	    if (localResource != null)
	    {
	      String[] arrayOfString = new String[2];
	      arrayOfString[0] = paramString1;
	      arrayOfString[1] = paramString2;
	      return localResource.getText(paramInt1, arrayOfString);
	    }
	    return "";
	  }

	  public String getString(int paramInt1, int paramInt2, String paramString1, String paramString2, String paramString3)
	  {
	    Resource localResource = (Resource)this.jm372.get(String.valueOf(paramInt2));
	    if (localResource != null)
	    {
	      String[] arrayOfString = new String[3];
	      arrayOfString[0] = paramString1;
	      arrayOfString[1] = paramString2;
	      arrayOfString[2] = paramString3;
	      return localResource.getText(paramInt1, arrayOfString);
	    }
	    return "";
	  }

	  public String getString(int paramInt1, int paramInt2, String paramString1, String paramString2, String paramString3, String paramString4)
	  {
	    Resource localResource = (Resource)this.jm372.get(String.valueOf(paramInt2));
	    if (localResource != null)
	    {
	      String[] arrayOfString = new String[4];
	      arrayOfString[0] = paramString1;
	      arrayOfString[1] = paramString2;
	      arrayOfString[2] = paramString3;
	      arrayOfString[3] = paramString4;
	      return localResource.getText(paramInt1, arrayOfString);
	    }
	    return "";
	  }

	  public String getString(int paramInt1, int paramInt2, String[] paramArrayOfString)
	  {
	    Resource localResource = (Resource)this.jm372.get(String.valueOf(paramInt2));
	    if (localResource != null)
	      return localResource.getText(paramInt1, paramArrayOfString);
	    return "";
	  }

	  public Resource getResource(String paramString, int paramInt)
	  {
	    return ((Resource)jm365(paramString).get(String.valueOf(paramInt)));
	  }

	  public Resource getResource(String paramString1, String paramString2)
	  {
	    return ((Resource)jm365(paramString1).get(paramString2));
	  }

	  public boolean clearCache()
	  {
	    return false;
	  }

	  public int cacheSize()
	  {
	    int i = 0;
	    Iterator localIterator = this.jm367.values().iterator();
	    while (localIterator.hasNext())
	      i += ((HashMap)localIterator.next()).size();
	    return i;
	  }

	  public Object cacheData()
	  {
	    return this.jm367;
	  }
}
